package com.elsa.smart_buffet.service.impl;

import com.elsa.smart_buffet.mapper.EvaluateMapper;
import com.elsa.smart_buffet.pojo.Evaluate;
import com.elsa.smart_buffet.pojo.ResultBox.CallBackMessage;
import com.elsa.smart_buffet.pojo.ResultBox.ResponseResult;
import com.elsa.smart_buffet.service.EvaluateService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Slf4j
@Transactional
public class EvaluateServiceImpl implements EvaluateService {

    @Autowired
    private EvaluateMapper evaluateMapper;

    @Override
    public ResponseResult selectAllEvaluate() {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.selectList(null));
    }

    @Override
    public ResponseResult selectOneByIdEvaluate(int id) {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.selectById(id));
    }

    @Override
    public ResponseResult updateEvaluate(Evaluate evaluate) {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.updateById(evaluate));
    }

    @Override
    public ResponseResult deleteByIdEvaluate(int id) {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.deleteById(id));
    }

    @Override
    public ResponseResult insertEvaluate(Evaluate evaluate) {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.insert(evaluate));
    }

    @Override
    public ResponseResult selectEvaluateByTime(String time) {
        String[] SplitTime = time.split("\\-");
        for(int i = 0; i < SplitTime.length; i++) {
            SplitTime[i] = SplitTime[i].replace("/", "-");
            log.info(SplitTime[i]);
        }
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.selectEvaluateByTime(SplitTime[0], SplitTime[1]));
    }

    @Override
    public ResponseResult selectEvaluateBySearchData(String data) {
        return new ResponseResult(CallBackMessage.SUCCESS, evaluateMapper.selectEvaluateBySearchData(data));
    }

}
